#求M中3,6,9组成的列表M=[[1,2,3],[4,5,6],[7,8,9]]
print([[i-2,i-1,i] for i in range(3,10,3)])

M=[[1,2,3],[4,5,6],[7,8,9]]
print([i[-1] for i in M])
#构建一个列表[(0,1),(1,2),(2,3),(3,4),(4,5),(5,6)]
print([(i,i+1) for i in range(6)])

#简化代码
def chain(*args):
    #'abc',(0,1,2)
    for it in args:
        for i in it:
            yield i


g=chain('abc',(0,1,2))
#print(list(g))['a', 'b', 'c', 0, 1, 2]
for i in g:#for 循环自动调用next
    print(i)


def chain(*args):
    # 'abc',(0,1,2)
    for it in args:
        yield from it# yield from优化了内存循环
g=chain('abc',(0,1,2))
for i in g:
    print(i)
